package _3装饰器模式;

abstract class Bird {
    public abstract int fly();
}

class Sparrow extends Bird {
    private final int DISTANCE = 100;

    @Override
    public int fly() {
        return this.DISTANCE;
    }
}

abstract class Decorator extends Bird {
    protected Bird bird;

    public Decorator() {}

    public Decorator(Bird bird) { this.bird = bird; }
}

class SparrowDecorator extends Decorator {
    private final int DISTANCE = 50;

    SparrowDecorator(Bird bird) {
        super(bird);
    }

    @Override
    public int fly() {
        return bird.fly() + this.eleFly();
    }

    private int eleFly() {
        return this.DISTANCE;
    }
}

public class Demo {
    public static void needBird(Bird bird) {
        int flyDistance = bird.fly();
        System.out.println("这只鸟可以飞" + flyDistance + "米");
    }

    public static void main(String[] args) {
        Sparrow sparrow = new Sparrow();
        needBird(sparrow);
        SparrowDecorator sparrowDecorator = new SparrowDecorator(sparrow);
        needBird(sparrowDecorator);
    }
}
